﻿using System;
using System.Windows.Forms;

namespace GameListEditor
{
    /// <summary> Displays filter. </summary>
    public partial class FormFilterDisplay : Form
    {        
        /// <summary> Initializes a new instance of the <see cref="T:System.Windows.Forms.Form" /> class. </summary>
        public FormFilterDisplay()
        {
            InitializeComponent();
        }

        /// <summary> Clears filter. </summary>
        public void Clear()
        {
            SetFilter(null);
        }

        ///-------------------------------------------------------------------------------------------------
        /// <summary> Sets filter text. </summary>
        /// <param name="sql"> The sql. </param>
        ///-------------------------------------------------------------------------------------------------
        public void SetFilter(String sql)
        {
            if (TEXT_Filter.InvokeRequired)
                TEXT_Filter.BeginInvoke(new MethodInvoker(delegate { SetFilter(sql); }));
            else
            {
                if (String.IsNullOrEmpty(sql))
                    TEXT_Filter.Clear();
                else
                    TEXT_Filter.Text = sql;
            }
        }

        ///-------------------------------------------------------------------------------------------------
        /// <summary> Event handler. Called by FormFilterDisplay for key down events. </summary>
        /// <param name="sender"> Source of the event. </param>
        /// <param name="e">      Key event information. </param>
        ///-------------------------------------------------------------------------------------------------
        private void FormFilterDisplay_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                Close();
        }
    }
}
